package com.quectel.cms.controller.sys;


import com.quectel.cms.controller.BaseController;
import com.quectel.constant.global.annotation.RequirePermissions;
import com.quectel.sys.module.sys.dto.mongo.SysLogDto;
import com.quectel.sys.module.sys.service.SysLogService;
import com.quectel.util.common.Page;
import com.quectel.util.common.Request;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author caolu
 * @email louis.cao@quectel.com
 * @date 2019-04-18 09:43:48
 */
@RestController
@RequestMapping("sysLog")
@Tag(name = "SysLogController", description = "系统日志相关api")
public class SysLogController extends BaseController {

    @DubboReference
    private SysLogService sysLogService;

    /**
     * 列表
     */
    @GetMapping("list")
    @RequirePermissions(values = "sysLog:list")
    @Operation(summary = "系统日志分页查询列表")
    public Response<Page<SysLogDto>> list(@RequestParam Map<String, Object> params) {
        Request request = Request.configParams(params);

        super.fillAuthorityData(params);

        List<SysLogDto> list = new ArrayList<>();
        int total = sysLogService.queryTotal(params);
        if (total > 0) {
            list = sysLogService.queryList(params);
        }
        Page<SysLogDto> page = new Page(request.getPageNo(), request.getPageSize(), total, list);
        return Response.<Page<SysLogDto>>ok().wrap(page);
    }


}
